<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>登录</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="CSS/login.css">
	<script type="text/javascript" src="JS/jquery-1.11.1.js"></script>

  </head>
  <style>
	body{background: url(images/nanxiong.png) no-repeat;}
	</style>
  
  	<body >
 
    <div id="login-form">
        <form method="post" action="loginAction" id="loginForm">
            <div class="user-name"><label for="user-name">用户名</label><input name="name" id="user-name" type="text" tabindex="1" value="请输入用户名" ></div>
            <div class="user-pw"><label for="user-pw2">密码</label><input name="pwd" id="user-pw1" type="password" value=""><input type="text" id="user-pw2" value="请输入密码"></div>
            <div class="login-btns"><button id="btn-ok" type="button">登录</button><button id="btn-cancel" type="button">取消</button> </div>
        </form>
        <div id="logintip" class="login-tips"><p >您输入的用户名不存在！</p></div>
    </div>
    
  </body>
 <% Object is = session.getAttribute("isLogin"); //读出Session里的登录判断
 	String isLogin="true";
 	if(is!=null){
 		isLogin = is.toString();
 	}
 %> 
  <script>
        jQuery( function(){
      //      $( "#btn-ok" ).click( function(){
        //       openWin();
       //                   } );
       var islogin="<%=isLogin%>";
    //   alert(islogin);
       if(islogin === "true"){
       		$("#logintip").hide();	
       	}else {
			$("#logintip").show();
		}
            formValidation();
            
        } );
        function openWin(){
            var iWidth =1280-10,iHeight=768-30;
            if (window.screen) {
                iWidth = screen.width;
                iHeight = screen.height;
            }
            var strFeatures = 'top=0,left=0,height='+iHeight+',width='+iWidth+',fullscreen=0,resizable=no,location=no,status=no,toolbar=no,channelmode=yes';
            var objWin= window.open('index.jsp',"openWin",strFeatures);

            // 关闭主窗口不提示确认信息
            window.open("","_self");
            window.close();
        };

        function formValidation(){
            var loginForm = $("#loginForm"),
                    userName = $("#user-name"),
                    userPw = $("#user-pw1"),
                    loginTips = $( '.login-tips' ),
                    showUserPw = $("#user-pw2"),
                    userNameVal = userName.val(),
                    userPwVal = userPw.val();

            userName.on({
                click: function(){
                    if($(this).val() == userNameVal){
                        $(this).val("").addClass("inputIng");
                    }else{
                        $(this).addClass("inputIng");
                    }
                },
                blur: function(){
                    if($(this).val()){
                        return;
                    }else{
                        $(this).val(userNameVal);
                        $(this).removeClass("inputIng");
                    }
                }
            });
            showUserPw.focus(function() {
                $(this).hide();
                userPw.show().focus();
            });
            userPw.on({
                blur: function(){
                    if($(this).val()){
                        return;
                    }else{
                        $(this).hide();
                        showUserPw.show();
                    }
                },
                keyup: function(e){

                    var postNameVal = userName.val(),
                            postPwVal = userPw.val();

                    if(e.keyCode == 13) {
                        if( postNameVal == "" || postNameVal == userNameVal ) {
                            userName.focus();
                            loginTips.text( '请输入用户名' );
                            return;
                        }
                        if( postPwVal == "" ){
                            showUserPw.focus();
                            loginTips.text( '请输入密码' );
                            return;
                        }
                        loginForm.submit();
                    }
                }
            });
            $(".login-btns button").on({
                mouseenter: function(){
                    $(this).addClass("state-hover");
                },
                mouseleave: function(){
                    $(this).removeClass("state-hover");
                },
                click: function(e){
                    if( $(e.target).attr( "id" ) == "btn-ok" ){
                        var postNameVal = userName.val(),
                                postPwVal = userPw.val();

                        if( postNameVal == "" || postNameVal == userNameVal ) {
                            userName.focus();
                            loginTips.text( '请输入用户名' );
                            return;
                        }
                        if( postPwVal == "" ){
                            showUserPw.focus();
                            loginTips.text( '请输入密码' );
                            return;
                        }
                        
                        loginForm.submit();
                    }
                }
            });
        };
    </script>
</html>
